#include "backlight.h"
#include "ui_backlight.h"
#include <QtWidgets/QPushButton>
#include <QtWidgets/QGridLayout>
#include <QMessageBox>
#include <QtWidgets/QDesktopWidget>
#define COLUMN_SPACING 20
int backTimeOut[8]={15,30,60,120,300,600,900,1800};
Backlight::Backlight(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Backlight)
{
    SetMainBacklight();
   

    ui->setupUi(this);
    ycapi = new Ycapi();

}
void Backlight::SetMainBacklight()
{
    QPalette bgpal = palette();
    bgpal.setColor (QPalette::Background, QColor (0, 0 , 0, 255));
    bgpal.setColor (QPalette::Foreground, QColor (255,0,0,255));
    setPalette (bgpal);
}
Backlight::~Backlight()
{
    delete ui;
}

void Backlight::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
void Backlight::on_D0_clicked()
{
     unsigned char  id[16];
     int i;
      ycapi->SetBacklightOn(0);    
}

void Backlight::on_D1_clicked()
{
      ycapi->SetBacklightOn(50);
}

void Backlight::on_D2_clicked()
{
      ycapi->SetBacklightOn(90);
}

void Backlight::on_D3_clicked()
{
      ycapi->SetBacklightOn(120);
}

void Backlight::on_D4_clicked()
{
      ycapi->SetBacklightOn(255);
}


void Backlight::on_close_clicked()
{
    this->close();
}

void Backlight::on_BackLightAutoEnable_clicked(bool checked)
{
    if(checked)
    {              
              ycapi->StartAutoBacklight(backTimeOut[ui->comboBoxBakTimeOut->currentIndex()]);
              ui->comboBoxBakTimeOut->setDisabled(true);
    }
    else
    {        ui->comboBoxBakTimeOut->setDisabled(false);
              ycapi->StopAutoBacklight();
    }
}

